package com.longge;

import java.util.Arrays;

public class MaximizeSquareHoleArea {

    public int maximizeSquareHoleArea(int n, int m, int[] hBars, int[] vBars) {

        int row = getLongCount(hBars);
        int col = getLongCount(vBars);

        return (int) Math.pow(Math.min(row, col) + 1, 2);
    }

    private int getLongCount(int[] arr) {

        Arrays.sort(arr);
        int ans = 1, count = 1;
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i] + 1 == arr[i + 1]) {
                count++;
                ans = Math.max(count, ans);
            } else {
                count = 1;
            }
        }
        return ans;
    }
}
